<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>所有退货申请</title>
</head>
<link href="/css/bootstrap.css" rel="stylesheet">
<script src="/js/jquery-2.1.4.js"></script>
<script src="/js/vue.js"></script>
<script src="/js/bootstrap.js"></script>
<style>
    #tb {
        text-align: center;
        font-size: small;
    }
</style>
<body>
<div id="div">
    <table class="table table-striped table-hover table-bordered" id="tb">
        <thead>
        <tr>
            <td width="20%">商品名称</td>
            <td width="12%">商品属性</td>
            <td width="5%">购买数量</td>
            <td width="5%">总价</td>
            <td width="10%">退款用户名</td>
            <td width="12%">退款原因</td>
            <td width="10%">退款申请时间</td>
            <td width="11%">状态</td>
            <td width="15%">操作</td>
        </tr>
        </thead>
        <tbody>
        <tr v-for="(returngood,index) in returngoods">
            <td v-text="returngood.productName"></td>
            <td v-text="returngood.property"></td>
            <td v-text="returngood.number"></td>
            <td v-text="returngood.money"></td>
            <td v-text="returngood.username"></td>
            <td v-text="returngood.reason"></td>
            <td v-text="returngood.time"></td>
            <td v-text="returngood.status==1?'待审核':returngood.status==2?'未通过':returngood.status==3?'已退费':returngood.status==4?
'运送中':'等待买家发货'"></td>
            <td>
                <input type="button"class="btn btn-primary btn-xs" @click="commitReturn(returngood.id,returngood.userId)" value="同意退货" v-if="returngood.status==1">
                <input type="button"class="btn btn-primary btn-xs" @click="rejectReturn(returngood.id)" value="拒绝退货" v-if="returngood.status==1">
                <input type="button"class="btn btn-primary btn-xs" @click="commitReturnMoney(returngood.id)" value="已收货，同意退款" v-if="returngood.status==4">
                <input type="button"class="btn btn-primary btn-xs" @click="rejectReturnMoney(returngood.id)" value="已收货，拒绝退款" v-if="returngood.status==4">
            </td>
        </tr>
        </tbody>
        <tfoot>
        <tr>
            <td colspan="9">
                <div>
                    总共<span v-text="page.dataCount"></span>条订单&nbsp;&nbsp;&nbsp;
                    当前是第<span v-text="page.pageIndex"></span>页&nbsp;&nbsp;&nbsp;
                    总共有<span v-text="page.pageCount"></span>页&nbsp;&nbsp;&nbsp;
                    <a href="javascript:" @click="prev()">上一页</a>&nbsp;&nbsp;&nbsp;
                    <a href="javascript:" @click="next()">下一页</a>&nbsp;&nbsp;&nbsp;
                </div>
            </td>
        </tr>
        </tfoot>
    </table>
</div>

<script type="text/javascript">
    new Vue({
        el: "#div",
        data: {
            returngoods: [],
            index: 1,
            number:2,
            page: null
        },
        created: function () {
            this.selectReturnGoods();
        },
        methods: {
            prev: function () {
                if (this.page.pageIndex == 1) {
                    alert("已经是首页");
                    return;
                }
                this.page.pageIndex = this.page.pageIndex - 1;
                this.index = this.page.pageIndex;
                this.selectReturnGoods();
            },
            next: function () {
                if (this.page.pageIndex == this.page.pageCount) {
                    alert("已经是尾页");
                    return;
                }
                this.page.pageIndex = this.page.pageIndex - (-1);
                this.index = this.page.pageIndex;
                this.selectReturnGoods();
            },
            selectReturnGoods: function () {
                var _this = this;
                $.ajax({
                    url: "/merchant/selectAllReturnGoods",
                    data: {
                        index: _this.index,
                        number: _this.number
                    },
                    dataType: "json",
                    type: "post",
                    success: function (data) {
                        _this.returngoods = data.list;
                        _this.page = data.obj;
// console.log(_this.orderviews[0].status==1?'待付款':_this.orderviews[0].status==2?'待发货':_this.orderviews[0].status==3?'待收货':'待评价');
                    },
                    error: function (data) {
                        alert(data.responseJSON.message);
                    }
                });
            },
            commitReturn:function (id,userId) {
                var _this=this;
                $.ajax({
                   url: "/merchant/commitReturn" ,
                    data:{
                       returnGoodsId:id,
                       userId:userId
                    },
                    dataType: "json",
                    type: "post",
                    success:function (data) {
                        alert("已同意退货，待买家发货");
                        location.reload();
                    },
                    error:function (data) {
                        alert(data.responseJSON.message);
                    }
                });
            },
            rejectReturn:function (id) {
                var _this=this;
                $.ajax({
                    url: "/merchant/rejectReturn" ,
                    data:{
                        returnGoodsId:id
                    },
                    dataType: "json",
                    type: "post",
                    success:function (data) {
                        alert("已拒绝买家退货申请");
                        location.reload();
                    },
                    error:function (data) {
                        alert(data.responseJSON.message);
                    }
                });
            },
            commitReturnMoney:function (id) {
                var _this=this;
                $.ajax({
                    url: "/merchant/commitReturnMoney" ,
                    data:{
                        returnGoodsId:id
                    },
                    dataType: "json",
                    type: "post",
                    success:function (data) {
                        alert("已同意退款，即将退款给用户");
                        location.reload();
                    },
                    error:function (data) {
                        alert(data.responseJSON.message);
                    }
                });
            },
            rejectReturnMoney:function (id) {
                var _this=this;
                $.ajax({
                    url: "/merchant/rejectAndAcceptGoods" ,
                    data:{
                        returnGoodsId:id
                    },
                    dataType: "json",
                    type: "post",
                    success:function (data) {
                        alert("已拒绝退款");
                        location.reload();
                    },
                    error:function (data) {
                        alert(data.responseJSON.message);
                    }
                });
            }
        }
    });
    </script>
    </body>
    </html>